package entities
{
	import parsers.MicroOBJParser;

	import flash.display.Bitmap;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DTextureFormat;
	import flash.display3D.Program3D;
	import flash.display3D.textures.Texture;
	import flash.geom.Matrix3D;
	/**
	 * @author perry
	 */
	public class MicroGZMMap extends MicroGZMEntity
	{
		[Embed (source = "textures/nullTexture.jpg")]
		private var mapTextureBitmap:Class;
		private var mapTextureData:Bitmap = new mapTextureBitmap();
		
		private var mapTexture:Texture;
		
		[Embed (source = "models/plane.obj", mimeType = "application/octet-stream")]
		private var modelData:Class;
		
		private var aceleration:Number;
		
		public function MicroGZMMap( contextIn:Context3D = null, shaderIn:Program3D = null,
									 textureIn:Texture = null, modelscale:Number = 1,
									 flipAxis:Boolean = true, flipTexture: Boolean = true )
		{
			
			transform = new Matrix3D();
			context = contextIn;
			shader = shaderIn;
			
			if( !textureIn )
			{
				mapTexture = context.createTexture( mapTextureData.width, mapTextureData.height, Context3DTextureFormat.BGRA, false);
				uploadTextureWithMipmaps( mapTexture, mapTextureData.bitmapData );
			}
			else
			{
				mapTexture = textureIn;
			}
			
			
			if (modelData && context)
			{
				mesh = new MicroOBJParser( modelData, context, modelscale, flipAxis, flipTexture );
				polycount = mesh.indexBufferCount;
				width = mesh.width;
				height = mesh.height;
				depth = mesh.depth;
			}
			
			texture = mapTexture;
		}

	}
}
